﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using System.Net;

namespace 智慧大棚课件
{
    public class Emailhelp
    {

        /// <summary>
        /// 发送邮件的方法
        /// </summary>
        /// <param name="mailForm">发件人地址</param>
        /// <param name="mailTo">接收人地址</param>
        /// <param name="mailTitle">标题</param>
        /// <param name="body">邮件的内容</param>
        /// <returns>邮件是否发送成功</returns>
        public static bool SendMail(string mailForm,string mailTo ,string mailTitle,string body)
        {

            // 发送邮件的对象
            SmtpClient smtpClient = new SmtpClient();
            // 发送邮件的地址
            smtpClient.Host = "smtp.qq.com";
            // 指定是否使用加密连接
            smtpClient.EnableSsl = true;
            // 
            smtpClient.UseDefaultCredentials = true;
            // 通过网络发送smtp邮件
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            // 设置发送的账号密码
            smtpClient.Credentials = new NetworkCredential("825846405@qq.com", "hbopaasdigcgbbbb");

            // 邮件类  包含发送者  接收者  标题   主体
            //MailMessage mailMessage = new MailMessage(mailForm,mailTo,mailTitle,body);
            try
            {
                smtpClient.Send(mailForm, mailTo, mailTitle, body);
                return true;
            }
            catch (Exception)
            {

                return false;
            }
            


        }




    }
}
